<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>请登陆系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <link type="text/css" href="common/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <script type="text/javascript" src="common/jquery/jquery-3.3.1.js"></script>
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <style>
        html,body{
            height: 100%;
        }
        body {
            display: -ms-flexbox;
            display: -webkit-box;
            display: flex;
            -ms-flex-align: center;
            -ms-flex-pack: center;
            -webkit-box-align: center;
            align-items: center;
            -webkit-box-pack: center;
            justify-content: center;
            padding-top: 40px;
            padding-bottom: 40px;
            background-color: #f5f5f5;
        }
        .form-signin{
            width: 100%;
            max-width: 330px;
            padding: 15px;
            margin: 0 auto;
        }
        .form-signin .checkbox{
            font-weight: 400;
        }
        #jcaptcha{
            display: inline-block;
            width: 50%;
            padding: .375rem .75rem;
            font-size: 1rem;
            line-height: 1.5;
            color: #495057;
            background-color: #fff;
            background-clip: padding-box;
            border: 1px solid #ced4da;
            border-radius: .25rem;
            transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
        }
    </style>
</head>
<body class="text-center">
    <form class="form-signin">
        <h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
        <label for="inputUsername" class="sr-only">Username</label>
        <input id="inputUsername" class="form-control" placeholder="Username" required type="text">
        <label for="inputPassword" class="sr-only">Password</label>
        <input id="inputPassword" class="form-control" placeholder="Password" required type="password">
        <div class="form-group mx-sm-3 mb-3" style="display: none">
            <input type="text" id="jcaptcha" placeholder="jcaptcha">&nbsp;&nbsp;&nbsp;
            <img src="" width="110" height="40">
        </div>
        <div class="checkbox mb-3">
            <label>
                <input type="checkbox" value="remember-me" id="rememberme"> Remember me
            </label>
        </div>
        <button class="btn btn-lg btn-primary btn-block" type="submit" id="sub">Sign in</button>
        <p class="mt-5 mb-3 text-muted">© 2017-2018</p>
    </form>
    <script type="text/javascript">
        $(function () {
            $("#sub").on("click", function(e) {
                e.preventDefault();
                var username = $("#inputUsername").val();
                var password = $("#inputPassword").val();
                var jcaptcha = $("#jcaptcha").val();
                var rememberme = $("#rememberme").val();
                $.ajax({
                    url: "/login",
                    method: "post",
                    data: {
                        userName: username,
                        password: password,
                        captcha: jcaptcha,
                        rememberMe: rememberme
                    },
                    success: function (data) {
                        if(data.messageCode == "012"){
                            $("#jcaptcha").parent().css("display","block");
                            $("img").attr("src", "/jcaptcha.jpg")
                        }else if(data.messageCode == "001"){
                            window.location.href = "/views/index.html";
                        }
                    }
                });
            });
        })
    </script>
</body>
</html>